package com.pijunn.users

import com.pijunn.common.MailingAddress;
import com.pijunn.label.Label;
import com.pijunn.security.SecUser;


class AppUser extends SecUser{

    static constraints = {
		username blank:false
		firstName blank: false
		lastName blank: false
		contactEMail (email:true, unique: true, blank: false)
		contactCellPhone()
		contactOtherPhone()
		contactSkypeId()
		password (password: true, blank: false)
    }
	
	static embedded = ['mailingAddress']
	
	static transients = ['captchaResponse']
	
	static hasMany = [assignedTags: Label]

	String firstName
	String lastName
	String contactEMail
	String contactCellPhone
	String contactOtherPhone
	String contactSkypeId
	MailingAddress mailingAddress
	Date createTime
	String captchaResponse
	
	String toString() {
		"${lastName}, ${firstName}"
	}
	
	int getAssignedLabelCount() {
		assignedTags.size()
	}
	
	int getRegisteredItemCount() {
		def i = 0
		for (tag in assignedTags) {
			if (tag.item)
				i++
		}
		
		return i
	}
}
